package coop.main.web.converter;
import coop.main.domain.Detalle;
import coop.main.service.DetalleService;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.roo.addon.jsf.converter.RooJsfConverter;

@Configurable
@FacesConverter("coop.main.web.converter.DetalleConverter")
@RooJsfConverter(entity = Detalle.class)
public class DetalleConverter implements Converter {

	@Autowired
    DetalleService detalleService;

	public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value == null || value.length() == 0) {
            return null;
        }
        Long id = Long.parseLong(value);
        return detalleService.findDetalle(id);
    }

	public String getAsString(FacesContext context, UIComponent component, Object value) {
        return value instanceof Detalle ? ((Detalle) value).getId().toString() : "";
    }
}
